<template>
  <div>
    <eagle-list
      showTab
      :tabData="tabData"
      @initActive="_initActive"
      @bindData="bindData"
    >
      <div v-if="this.active === 0">
        <div class="check-list">
          <div class="check-sum">
            <van-notice-bar
              color="#323233"
              background="#fff"
            >
              当前已检查{{ totalnum }}项,其中不符合{{ noNum }}项
            </van-notice-bar>
          </div>
          <div class="check-content">
            <!-- <div class="add" @click="edit(form.ID)">编辑</div> -->
            <van-collapse
              v-model="activeNames"
              accordion
            >
              <template v-for="(item, index) in list">
                <van-collapse-item
                  :name="index + 1"
                  :key="index"
                >
                  <template #title>
                    <div class="checklist-title">
                      <img
                        class="title-logo"
                        src="@/assets/Images/AppIcon/fragment_noticetype_3.png"
                        alt=""
                      />
                      {{ item.DetailItemName }} | 共{{
                        item.children.length
                      }}个项目
                    </div>
                  </template>

                  <div
                    v-for="(innerItem, innerIndex) in item.children"
                    :key="innerIndex"
                  >
                    <div class="color-gray1">
                      {{ innerIndex + 1 }}、{{ innerItem.DetailItemName }}
                    </div>
                    <div class="accord-btns mt-10">
                      <div
                        class="accord-btn"
                        @click="handleClick(index, innerIndex, 'Y')"
                        :class="
                          innerItem.CheckResult == 'Y' && innerItem.checked
                            ? 'active'
                            : ''
                        "
                      >
                        符合
                      </div>
                      <div
                        class="accord-btn"
                        @click="handleClick(index, innerIndex, 'N')"
                        :class="
                          innerItem.CheckResult == 'N' && innerItem.checked
                            ? 'inconformity'
                            : ''
                        "
                      >
                        不符合
                      </div>
                      <div
                        class="accord-btn"
                        @click="handleClick(index, innerIndex, 'NA')"
                        :class="
                          innerItem.CheckResult == 'NA' && innerItem.checked
                            ? 'not-applicable'
                            : ''
                        "
                      >
                        不适用
                      </div>
                    </div>
                    <van-form v-if="
                        (innerItem.CheckResult == 'Y' ||
                          innerItem.CheckResult == 'NA') &&
                          innerItem.checked
                      ">
                      <div class="inconformity-list">
                        <van-row>
                          <van-col
                            span="4"
                            offset="1"
                          >备注</van-col>
                          <van-col span="24">
                            <van-field
                              v-model="innerItem.Remarks"
                              rows="3"
                              autosize
                              type="textarea"
                              maxlength="50"
                              placeholder="请输入"
                            />
                          </van-col>
                        </van-row>
                      </div>
                    </van-form>
                    <van-form v-if="innerItem.CheckResult == 'N' && innerItem.checked">
                      <div class="inconformity-list">
                        <div>
                          <eagle-image-uploader
                            class="ml-10"
                            :images.sync="innerItem.Attachs"
                          ></eagle-image-uploader>
                          <div>
                            <div>
                              <van-field
                                class="input_text"
                                label="隐患区域"
                                input-align="right"
                              >
                                <template #input>
                                  <div
                                    style="display: flex; color: #1296db"
                                    @click="showDangerArea(index, innerIndex)"
                                  >
                                    <img
                                      src="@/assets/Images/AppIcon/icon_danger_select.png"
                                      alt=""
                                    />
                                    选择隐患区域
                                  </div>
                                </template>
                              </van-field>
                            </div>
                            <van-field v-model="innerItem.HiddenDangerArea" />
                          </div>
                          <div>
                            <div>
                              <van-field
                                class="input_text"
                                label="隐患描述"
                                required
                                input-align="right"
                              >
                                <template #input>
                                  <div></div>
                                </template>
                              </van-field>
                            </div>
                            <van-field
                              v-model="innerItem.HiddenDangerDesc"
                              rows="3"
                              autosize
                              type="textarea"
                            />
                          </div>
                          <template v-if="isManager">
                            <van-field
                              class="input_text"
                              :value="getLGDText(innerItem)"
                              label="隐患分类"
                              placeholder="请选择"
                              required
                              readonly
                              @click="showDangerType(index, innerIndex)"
                            >
                              <template #right-icon>
                                <van-icon name="arrow" />
                              </template>
                            </van-field>
                            <!-- 单选框 -->
                            <van-field
                              class="input_text"
                              name="radio"
                              label="隐患性质"
                              required
                            >
                              <template #input>
                                <van-radio-group
                                  v-model="innerItem.HiddenDangerType"
                                  direction="horizontal"
                                >
                                  <van-radio
                                    name="1"
                                    style="margin: 0 10px 10px 0"
                                  >一般隐患</van-radio>

                                  <van-radio
                                    name="2"
                                    style="margin: 0 10px 10px 0"
                                  >重大隐患</van-radio>
                                </van-radio-group>
                              </template>
                            </van-field>
                            <van-field
                              class="input_text"
                              :value="getCorrectUserText(innerItem)"
                              label="整改部门/人"
                              placeholder="请选择"
                              required
                              readonly
                              @click="showDeprtartmentUser(index, innerIndex)"
                            >
                              <template #right-icon>
                                <van-icon name="arrow" />
                              </template>
                            </van-field>
                            <!-- 日期 Date-->
                            <date-picker
                              label="整改期限"
                              :required="innerItem.IsMustSubCorrectiveDate"
                              showFastSelect="true"
                              :date.sync="innerItem.CorrectiveDate"
                            ></date-picker>
                          </template>
                        </div>
                      </div>
                    </van-form>
                    <van-divider />
                  </div>
                </van-collapse-item>
              </template>
            </van-collapse>
          </div>
        </div>
      </div>
      <div v-if="this.active === 1">
        <eagle-cell
          v-for="(item, index) in list"
          :key="index"
          class="card"
        >
          <eagle-tag
            v-if="item.Status == 0"
            class="info_tag"
            color="grey"
          >未开始</eagle-tag>
          <div class="warn_item">
            <div>
              <eagle-row>
                <eagle-col span="24">
                  {{ index + 1 }}、{{ item.name }}</eagle-col>
              </eagle-row>

              <eagle-row
                gutter="20"
                class="dep_sort"
              >
                <eagle-col span="12">
                  <img
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                    alt=""
                  />{{ item.cnt }}
                </eagle-col>
              </eagle-row>
            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-list>
  </div>
</template>
<script>
export default {
  data() {
    return {
      active: 0,
      activeNames: 1,
      tabData: [
        {
          title: "进行中的任务",
          url: "/DangerCheckTaskDetail/GetDetailTemplateData",
          params: {
            tCode: "TC21110800002",
          },
        },
        {
          title: "进行中的任务2",
          url: "/DangerCheckTaskDetail/GetDetailTemplateData",
          params: {
            tCode: "TC21092800005",
          },
        },
      ],
      list: [],
      totalnum: 0,
      noNum: 0,
      DangerSimpleType: "",
      DangerSimpleType: "",
    };
  },
  methods: {
    _initActive(active) {
      this.active = active;
    },
    bindData(data) {
      
      let newList = [];
      this.DangerSimpleType = "";
      data.map((item, index) => {
        let innerobj = {};
        if (item.ID === -1) {
          innerobj = item;
          innerobj.children = [];
          data.map((innerItem, innerIndex) => {
            if (innerItem.SEQ === item.SEQ && innerItem.ID != -1) {
              innerItem.checked = innerItem.CheckResult;
              innerItem.HiddenDangerType = innerItem.HiddenDangerType || "1";
              if (this.$route.query.areaCode) {
                innerItem.HiddenDangerAreaCode = this.$route.query.areaCode;
                innerItem.IsAssignedArea = true;
              }
              if (this.$route.query.areaName) {
                innerItem.HiddenDangerArea = this.$route.query.areaName;
              }
              if (this.$route.query.areaType) {
                innerItem.HiddenDangerAreaType = this.$route.query.areaType;
              }
              if (this.$route.query.areaNo) {
                innerItem.HiddenDangerAreaNo = this.$route.query.areaNo;
              }
              if (innerItem.DangerSimpleType == "A") {
                this.DangerSimpleType = "A";
              }
              innerobj.children.push(innerItem);
            }
          });
          newList.push(innerobj);
        }
      });
      this.list = newList;
    },
    // 点击符合、不符合
    handleClick(index, innerIndex, CheckResult) {
      this.list.forEach((item, idx) => {
        if (index == idx) {
          item.children.forEach((v, i) => {
            if (i == innerIndex) {
              if (v.CheckResult == CheckResult) {
                v.checked = !v.checked;
                v.CheckResult = "";
              } else {
                v.checked = true;
                v.CheckResult = CheckResult;
              }
            }
          });
        }
      });
      this.calcNum();
    },
    calcNum() {
      let totalnum = 0;
      let noNum = 0;
      this.list.map((item, idx) => {
        item.children.map((innerItem, innerIds) => {
          if (innerItem.CheckResult != "" && innerItem.CheckResult != null) {
            console.log("innerItem.CheckResult", innerItem.CheckResult);
            totalnum++;
          }
          if (innerItem.CheckResult == "N") {
            noNum++;
          }
        });
      });
      this.totalnum = totalnum;
      this.noNum = noNum;
    },
  },
};
</script>

<style lang="less" scoped>
.total-count {
  display: flex;
  align-items: center;
}
</style>
<style lang="less" scoped>
.check-list {
  min-height: 100vh;
  padding-bottom: 100px;
  background-color: #e8f1f8;
}
.checklist-title {
  display: flex;
  align-items: center;
}
.title-logo {
  width: 15px;
  height: 16px;
  margin-right: 10px;
}
// 符合按钮
.accord-btns {
  display: flex;
  align-items: center;
  justify-content: space-between;
  .accord-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30%;
    height: 22px;
    background-color: #fff;
    color: #666;
    font-size: 12px;
  }
  .active {
    background-color: #1989fa;
    color: #fff;
  }
  .inconformity {
    background-color: #ee0a24;
    color: #fff;
  }
  .not-applicable {
    background-color: #ff976a;
    color: #fff;
  }
}
.inconformity-list {
  background-color: #fff;
  margin-top: 10px;
  padding-top: 10px;
}
/*
        .main {
            height: 100vh;
        }
    */

.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}
.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}

.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}
.operate_det {
  background-color: #fff;
  padding: 10px;
  .operate_list {
    border: 1px solid #e8f1f8;
    .operate_row_first {
      padding: 10px;
      background-color: #e8f1f8;
      border-bottom: 1px solid #e8f1f8;
      margin-bottom: 10px;
    }
    .operate_row {
      padding: 10px;
      border-bottom: 1px solid #e8f1f8;
      /*margin-bottom: 10px;*/
    }
  }
}

.bottom-buttons {
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  .submit-button,
  .save-btn {
    border: none;
    border-radius: 0;
  }
  .submit-button {
    width: 70%;
  }
  .save-btn {
    width: 30%;
  }
}
.van-divider {
  border-color: #ccc;
}
</style>
<style lang="less">
.check-list {
  .van-collapse {
    .van-collapse-item__content {
      background-color: #e8f1f8;
      padding: 10px 10px 0px 10px;
    }
  }
}
.check-sum {
  position: fixed;
  top: 2.5rem;
  left: 0px;
  width: 100%;
  z-index: 1000;
}

.check-content {
  margin-top: 45px;
}
</style>
